home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / game / wins1726.zip / MAINFRAC.C < prev    next >
C/C++ Source or Header  |  1992-06-07  |  16KB  |  626 lines

  1. /*
  2.    non-windows main driver of Fractint for Windows -
  3. */
  4.  
  5.  
  6. #define PUTTHEMHERE 1        /* stuff common external arrays here */
  7.  
  8. void win_cmdfiles();
  9.  
  10. /* from MSC's <dos.h> */
  11. #define FP_SEG(fp) (*((unsigned _far *)&(fp)+1))
  12. #define FP_OFF(fp) (*((unsigned _far *)&(fp)))
  13.  
  14. #include "fractint.h"
  15. #include "fractype.h"
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <search.h>
  20. #include <string.h>
  21. #include <float.h>
  22. #include <ctype.h>
  23. #include <time.h>
  24.  
  25. int cmp_line(), pot_line();
  26.  
  27. LPSTR win_lpCmdLine;
  28.  
  29. extern int time_to_restart;
  30. extern int time_to_reinit;
  31. extern int time_to_resume;
  32. extern int time_to_quit;
  33. extern int time_to_load;
  34. extern int time_to_save;
  35. extern int time_to_print;
  36. extern int time_to_cycle;
  37. extern int time_to_starfield;
  38. extern int time_to_orbit;
  39.  
  40. extern char FileName[];
  41. char string004[2];
  42.  
  43. unsigned char textcolor[27];
  44.  
  45. extern int xdots, ydots, colors, maxiter;
  46. extern int ytop, ybottom, xleft, xright;
  47.  
  48. int fractype;
  49. extern int invert;
  50.  
  51. double ftemp, xxmin, xxmax, yymin, yymax;
  52. long fudge;
  53. double xfudge;
  54.  
  55. long xvalue, yvalue;
  56. extern long lm, linitx, linity;
  57. int maxit, bitshift;
  58. extern int color, row, col;
  59. extern    int colorstate,colorpreloaded;    /* comments in cmdfiles */
  60.  
  61. int calc_status; /* -1 no fractal            */
  62.          /*  0 parms changed, recalc reqd   */
  63.          /*  1 actively calculating        */
  64.          /*  2 interrupted, resumable        */
  65.          /*  3 interrupted, not resumable   */
  66.          /*  4 completed            */
  67.  
  68. extern int reset_periodicity;
  69. extern int cpu;
  70. extern int kbdcount;
  71. extern int max_kbdcount;
  72. extern int show_orbit;
  73. extern int orbit_ptr;
  74. extern int periodicitycheck;
  75. extern int debugflag;
  76. int integerfractal;
  77. extern int distest;
  78. int oktoprint = 0;
  79. extern int bitshiftless1;
  80. char usr_stdcalcmode, stdcalcmode;
  81. int  usr_distest;
  82. int usr_floatflag, usr_periodicitycheck;
  83.  
  84. long creal, cimag;
  85. long delx, dely, delx2, dely2, delmin;
  86. long xmin, xmax, ymin, ymax, x3rd, y3rd;
  87. double  dxsize, dysize;        /* xdots-1, ydots-1        */
  88. double delxx, delyy, delxx2, delyy2, ddelmin, xx3rd, yy3rd;
  89. double param[4];
  90. double potparam[3];
  91. int diskvideo, savedac;
  92. long calctime;
  93. int mode7text, textsafe;
  94.  
  95. #define MAXLINE  2048
  96.  
  97. long   far *lx0, far *ly0, far *lx1, far *ly1;
  98. double far *dx0, far *dy0, far *dx1, far *dy1;
  99. extern double far *temp_array;
  100.  
  101. extern unsigned char trigndx[4];
  102.  
  103. unsigned char dacbox[257][3];
  104. extern unsigned char olddacbox[257][3];
  105. double plotmx1, plotmx2, plotmy1, plotmy2;
  106. extern int MPOverflow;
  107. int dotmode;
  108. extern int pot16bit;
  109. int andcolor, resave_flag;
  110. extern int timer_interval;
  111. extern int active_ovly;
  112.  
  113. int extraseg;
  114. int timedsave = 0;
  115. int disk16bit = 0;
  116. extern int initbatch;
  117. float far initifs3d[32][13];
  118. float far initifs[32][7];
  119. extern unsigned char readname[];
  120. int rowcount;
  121. int adapter;
  122. extern int showfile;
  123. extern int initmode;
  124. extern int overlay3d;
  125. extern int display3d;
  126. extern int filetype;
  127. int comparegif = 0;
  128. int diskisactive = 0;
  129. extern int initsavetime;
  130. int saveticks = 0;
  131. int savebase = 0;
  132. int zwidth = 0;
  133. extern int (*outln)();
  134. extern int out_line();
  135. extern int outlin16();
  136. static int call_line3d();
  137. extern int line3d();
  138. extern int gifview();
  139. extern int tgaview();
  140. int hasconfig = 0;
  141. FILE *dacfile;
  142. int reallyega = 0;
  143. int loadPalette = 0;
  144. int compiled_by_turboc = 0;
  145.  
  146. int     sxdots,sydots;
  147. int     sxoffs=0,syoffs=0;
  148. int     viewwindow=0;
  149. float   viewreduction=1;
  150. int     viewcrop=1;
  151. float   finalaspectratio;
  152. int     viewxdots=0,viewydots=0;
  153. extern int filexdots, fileydots, filecolors;
  154. int frommandel;
  155.  
  156. int onthelist[100];        /* list of available fractal types */
  157. int CountFractalList;           /* how many are on the list? */
  158. extern int CurrentFractal;        /* which one is current? */
  159.  
  160. int Printer_Resolution, Printer_Titleblock, Printer_SFrequency;
  161. int Printer_SetScreen, Printer_SStyle, Printer_Type;
  162. int Printer_ColorXlat, Printer_SAngle, LPTnumber;
  163. int EPSFileType, Print_To_File, Printer_CRLF;
  164. int ColorPS;
  165. int Printer_BFrequency, Printer_BStyle, Printer_BAngle;
  166. int Printer_GFrequency, Printer_GStyle, Printer_GAngle;
  167. int Printer_RFrequency, Printer_RStyle, Printer_RAngle;
  168.  
  169. int tabmode, video_type, no_color_text;
  170.  
  171. long    l_at_rad;        /* finite attractor radius  */
  172. double    f_at_rad;        /* finite attractor radius  */
  173.  
  174.  
  175. int active_system = WINFRAC;    /* running under windows */
  176. extern int win_display3d, win_overlay3d;
  177.  
  178. int iit = 0;
  179. int vesa_detect;
  180. int far videotable[2];
  181. int release;
  182. extern int win_release;
  183. char busy;
  184. int started_resaves = 0;
  185. int gotrealdac = 1;
  186. void    (*outln_cleanup)();
  187. extern int fpu;
  188. int svga_type = 0;
  189. int TranspSymmetry;
  190.  
  191. int made_dsktemp = 0;
  192.  
  193. compare_fractalnames( const void *element1, const void *element2)
  194. {
  195. int i, j, k;
  196.     j = *(int*)element1;
  197.     k = *(int*)element2;
  198. for (i = 0; i < 100; i++) {
  199.     if (fractalspecific[j].name[i] < fractalspecific[k].name[i])
  200.         return(-1);
  201.     if (fractalspecific[j].name[i] > fractalspecific[k].name[i])
  202.         return(1);
  203.     if (fractalspecific[j].name[i] == 0)
  204.         return(0);
  205.     }
  206. return(0);
  207. }
  208.  
  209. fractint_main()
  210. {
  211. int i, k;
  212. double temp1, temp2;
  213. double dtemp;
  214.  
  215. outln_cleanup = NULL;        /* outln routine can set this */
  216.  
  217. CountFractalList = 0;
  218. for (k = 0; fractalspecific[k].name != NULL; k++)
  219.    if (fractalspecific[k].name[0] != '*' &&
  220.        (fractalspecific[k].flags & WINFRAC) != 0 &&
  221.        CountFractalList < 100) 
  222.             onthelist[CountFractalList++] = k;
  223. qsort(onthelist,CountFractalList,2,compare_fractalnames);
  224. CurrentFractal = fractype;
  225.  
  226. lx0 = (long far *)&temp_array[0];
  227. ly0 = (long far *)&lx0[MAXLINE];
  228. lx1 = (long far *)&ly0[MAXLINE];
  229. ly1 = (long far *)&ly0[MAXLINE];
  230. dx0 = (double far *)&temp_array[0];
  231. dy0 = (double far *)&dx0[MAXLINE];
  232. dx1 = (double far *)&dy0[MAXLINE];
  233. dy1 = (double far *)&dy0[MAXLINE];
  234.  
  235. extraseg = FP_SEG(dx0);
  236.  
  237. restoredac();        /* ensure that the palette has been initialized */
  238.  
  239. win_cmdfiles();                /* SSTOOLS.INI processing */
  240.  
  241. initmode = 1;                           /* override SSTOOLS.INI */
  242.  
  243. release = win_release;
  244.  
  245. dotmode = 1;
  246. diskvideo = 0;
  247. usr_distest = 0;
  248.  
  249. max_kbdcount=(cpu==386) ? 80 : 30; /* check the keyboard less often */
  250.  
  251. /* ----- */
  252.  
  253. calc_status = -1;
  254. resave_flag = 1;
  255. strcpy(FileName,"Fract001");
  256. if (showfile != 0) {
  257.     strcpy(readname, FileName);
  258.     }
  259. else {
  260.     if (strchr(readname,'.') == NULL)
  261.      strcat(readname,".gif");
  262.     strcpy(FileName,readname);
  263.     time_to_load = 1;
  264.     }
  265.  
  266. if (debugflag == 23232) {   /* check for free memory */
  267.    char temp[50];
  268.    sprintf(temp," %d bytes of free stack space",stackavail());
  269.    stopmsg(0,temp);
  270.    }
  271.  
  272. if (debugflag == 70) fpu = 0;
  273.  
  274. init_help();
  275.  
  276. /* ----- */
  277.  
  278. time_to_quit = 0;
  279. if (debugflag == 23232) /* give the Windows stuff control first */
  280.     getakey(); 
  281. if (time_to_quit) {
  282.     end_help();
  283.     return(0);
  284.     }
  285.  
  286. reinit:
  287.     time_to_reinit = 0;
  288.  
  289.     savedac = 0;             /* don't save the VGA DAC */
  290.  
  291.     for (i = 0; i < 4; i++) {
  292.         if(param[i] != FLT_MAX)
  293.             fractalspecific[fractype].paramvalue[i] = param[i];
  294.         else
  295.             param[i] = fractalspecific[fractype].paramvalue[i];
  296.         }
  297.  
  298. /*  Not used, MCP 8-6-91
  299.     ccreal = param[0]; ccimag = param[1]; */ /* default C-values */
  300.     frommandel = 0;
  301.  
  302.     if (xxmin > xxmax) {
  303.        dtemp = xxmin; xxmin = xxmax; xxmax = dtemp;} 
  304.     if (yymin > yymax) {
  305.        dtemp = yymin; yymin = yymax; yymax = dtemp;} 
  306.  
  307.     ytop    = 0;
  308.     ybottom = ydots-1;
  309.     xleft   = 0;
  310.     xright  = xdots-1;
  311.     filexdots = xdots;
  312.     fileydots = ydots;
  313.     filecolors = colors;
  314.  
  315. restart:
  316.     time_to_restart = 0;
  317.     time_to_resume = 0;
  318.     time_to_orbit = 0;
  319.  
  320.     win_title_text(" (calculating)");
  321.  
  322.     if (calc_status == -99)
  323.         calc_status = 2;            /* force a recalc */
  324.     else
  325.         calc_status = 0;            /* force a restart */
  326.  
  327.     maxit = maxiter;
  328.  
  329.     if (colors == 2 && (fractype == PLASMA || usr_stdcalcmode == 'b'))
  330.         colors = 16;         /* 2-color mode just doesn't work on these */
  331.  
  332.     andcolor = colors-1;
  333.  
  334.     /* compute the (new) screen co-ordinates */
  335.     /* correct a possibly munged-up zoom-box outside the image range */
  336.     if (ytop    >= ydots) ytop    = ydots-1;
  337.     if (ybottom >= ydots) ybottom = ydots-1;
  338.     if (xleft   >= xdots) xleft   = xdots-1;
  339.     if (xright  >= xdots) xright  = xdots-1;
  340.     if (xleft == xright || ytop == ybottom) {
  341.         }
  342.     if (xleft > xright)
  343.         { i = xleft; xleft = xright; xright = i;}
  344.     if (ytop > ybottom)
  345.         { i = ybottom; ybottom = ytop; ytop = i;}
  346.     temp1 = xxmin;
  347.     temp2 = xxmax - xxmin;
  348.     xxmin = temp1 + (temp2 * xleft )/(xdots-1);
  349.     xxmax = temp1 + (temp2 * xright)/(xdots-1);
  350.     temp1 = yymin;
  351.     temp2 = yymax - yymin;
  352.     yymin = temp1 + (temp2 * (ydots - 1 - ybottom)/(ydots-1));
  353.     yymax = temp1 + (temp2 * (ydots - 1 - ytop   )/(ydots-1));
  354.     xx3rd = xxmin;
  355.     yy3rd = yymin;
  356.     xleft   = 0;
  357.     xright  = xdots-1;
  358.     ytop    = 0;
  359.     ybottom = ydots-1;
  360.  
  361. /*
  362.     delxx = (xxmax - xxmin) / (xdots-1);
  363.     delyy = (yymax - yymin) / (ydots-1);
  364.     delxx2 = delyy2 = 0.0;
  365.     ddelmin = fabs(delxx);
  366.     if (fabs(delyy) < ddelmin)
  367.         ddelmin = fabs(delyy);
  368. */
  369.  
  370.     dxsize = xdots - 1;  dysize = ydots - 1;
  371.  
  372.     if (calc_status != 2 && !overlay3d)
  373.         if (!clear_screen(1)) {
  374.             stopmsg(0,"Can't free and re-allocate the image");
  375.             return(0);
  376.             }
  377.  
  378.     if (savedac || colorpreloaded) {
  379.         memcpy(dacbox,olddacbox,256*3); /* restore the DAC */
  380.         spindac(0,1);
  381.         colorpreloaded = 0;
  382.         }
  383.  
  384.     dxsize = xdots - 1;  dysize = ydots - 1;
  385.     sxdots = xdots;  sydots = ydots;
  386.     finalaspectratio = ((float)ydots)/xdots;
  387.  
  388.     calcfracinit();
  389.  
  390.     bitshiftless1 = bitshift - 1;
  391.  
  392.     if (time_to_load)
  393.         goto wait_loop;
  394.  
  395.       if(showfile == 0) {        /* loading an image */
  396.      if (display3d)         /* set up 3D decoding */
  397.         outln = call_line3d;
  398.      else if(filetype >= 1)     /* old .tga format input file */
  399.         outln = outlin16;
  400.      else if(comparegif)        /* debug 50 */
  401.         outln = cmp_line;
  402.      else if(pot16bit) {        /* .pot format input file */
  403.         pot_startdisk();
  404.         outln = pot_line;
  405.         }
  406.      else                /* regular gif/fra input file */
  407.         outln = out_line;
  408.      if(filetype == 0)
  409.         i = funny_glasses_call(gifview);
  410.      else
  411.         i = funny_glasses_call(tgaview);
  412.      if(i == 0)
  413.         buzzer(0);
  414.      else {
  415.         calc_status = -1;
  416.         }
  417.      }
  418.  
  419.       if(showfile == 0) {        /* image has been loaded */
  420.      showfile = 1;
  421.      if (initbatch == 1 && calc_status == 2)
  422.         initbatch = -1; /* flag to finish calc before save */
  423.      if (calc_status == 2) goto try_to_resume;
  424.      }
  425.       else {                /* draw an image */
  426.  
  427. try_to_resume:
  428.  
  429.      diskisactive = 1;        /* flag for disk-video routines */
  430.      if (initsavetime != 0        /* autosave and resumable? */
  431.        && (fractalspecific[fractype].flags&NORESUME) == 0) {
  432.         savebase = readticker(); /* calc's start time */
  433.         saveticks = (long)initsavetime * 1092; /* bios ticks/minute */
  434.         if ((saveticks & 65535) == 0)
  435.            ++saveticks; /* make low word nonzero */
  436.         }
  437.          kbdcount = 30;                 /* ensure that we check the keyboard */
  438.      if ((i = calcfract()) == 0)    /* draw the fractal using "C" */
  439.         buzzer(0); /* finished!! */
  440.          saveticks = 0;         /* turn off autosave timer */
  441.          diskisactive = 0;        /* flag for disk-video routines */
  442.      }
  443.  
  444.     overlay3d = 0;      /* turn off overlay3d */
  445.     display3d = 0;      /* turn off display3d */
  446.  
  447.     zwidth = 0;
  448.  
  449.     if (!keypressed()) {
  450.         flush_screen();
  451.         buzzer(3);
  452.         win_title_text("");
  453.         getakey();
  454.         }
  455.  
  456. wait_loop:
  457.  
  458.     win_title_text("");
  459.  
  460. for (;;) {
  461.     if (time_to_quit) {
  462.          end_help();
  463.          return(0);
  464.          }
  465.     if (time_to_starfield) {
  466.          time_to_starfield = 0;
  467.          win_title_text("(Starfield Generation)");
  468.          starfield();
  469.          win_title_text("");
  470.          flush_screen();
  471.          }
  472.     if (time_to_load) {
  473.         strcpy(readname, FileName);
  474.         showfile = 1;
  475.         time_to_load = 0;
  476.         time_to_restart = 0;
  477.         overlay3d = win_overlay3d;
  478.         display3d = win_display3d;
  479.         if (win_load() >= 0) {
  480.             showfile = 0;
  481.             rowcount = 0;
  482.             ytop    = 0;        /* reset the zoom-box */
  483.             ybottom = ydots-1;
  484.             xleft   = 0;
  485.             xright  = xdots-1;
  486.             maxiter = maxit;
  487.             time_to_load = 0;
  488.             time_to_restart = 1;
  489.             if (calc_status == 2) {
  490.                 calc_status = -99;      /* special klooge for restart */
  491.                 }
  492.             }
  493.         win_overlay3d = 0;
  494.         win_display3d = 0;
  495.         }
  496.     if (time_to_save) {
  497.         strcpy(readname, FileName);
  498.         if (readname[0] != 0)
  499.             win_save();
  500.         time_to_save = 0;
  501.         if (calc_status == 2) {
  502.             calc_status = -99;
  503.             time_to_restart = 1;
  504.             }
  505.         }
  506.     if (time_to_print) {
  507.         win_print();
  508.         time_to_print = 0;
  509.         }
  510.     if (time_to_cycle) {
  511.        win_cycle();
  512.        }
  513.     if (time_to_reinit)
  514.          goto reinit;
  515.     if(time_to_restart)
  516.          goto restart;
  517.     if(time_to_resume)
  518.         if (calc_status == 2) {
  519.             calc_status = -99;
  520.             time_to_restart = 1;
  521.             goto restart;
  522.             }
  523.     getakey();
  524.     }
  525.  
  526. }
  527.  
  528. /* displays differences between current image file and new image */
  529. /* Bert - suggest add this to video.asm */
  530. int cmp_line(unsigned char *pixels, int linelen)
  531. {
  532.    static errcount;
  533.    static FILE *fp = NULL;
  534.    extern int rowcount;
  535.    int row,col;
  536.    int oldcolor;
  537.    char *timestring;
  538.    time_t ltime;
  539.    if(fp == NULL)
  540.       fp = fopen("cmperr",(initbatch)?"a":"w");
  541.    if((row = rowcount++) == 0)
  542.       errcount = 0;
  543.    if(pot16bit) { /* 16 bit info, ignore odd numbered rows */
  544.       if((row & 1) != 0) return(0);
  545.       row >>= 1;
  546.       }
  547.    for(col=0;col<linelen;col++) {
  548.       oldcolor=getcolor(col,row);
  549.       if(oldcolor==pixels[col])
  550.      putcolor(col,row,0);
  551.       else {
  552.      if(oldcolor==0)
  553.         putcolor(col,row,1);
  554.      ++errcount;
  555.      if(initbatch == 0)
  556.         fprintf(fp,"#%5d col %3d row %3d old %3d new %3d\n",
  557.            errcount,col,row,oldcolor,pixels[col]);
  558.      }
  559.       }
  560.    if(row+1 == ydots && initbatch) {
  561.       time(<ime);
  562.       timestring = ctime(<ime);
  563.       timestring[24] = 0; /*clobber newline in time string */
  564.       fprintf(fp,"%s compare to %s has %5d errs\n",timestring,readname,errcount);
  565.       }
  566.    return(0);
  567. }
  568.  
  569. int pot_line(unsigned char *pixels, int linelen)
  570. {
  571.    extern int rowcount;
  572.    int row,col,saverowcount;
  573.    if (rowcount == 0)
  574.       pot_startdisk();
  575.    saverowcount = rowcount;
  576.    row = (rowcount >>= 1);
  577.    if ((saverowcount & 1) != 0) /* odd line */
  578.       row += ydots;
  579.    else             /* even line */
  580.       if (dotmode != 11) /* display the line too */
  581.      out_line(pixels,linelen);
  582.    for (col = 0; col < xdots; ++col)
  583.       writedisk(col+sxoffs,row+syoffs,*(pixels+col));
  584.    rowcount = saverowcount + 1;
  585.    return(0);
  586. }
  587.  
  588. static int call_line3d(unsigned char *pixels, int linelen)
  589. {
  590.    /* this routine exists because line3d might be in an overlay */
  591.    return(line3d(pixels,linelen));
  592. }
  593.  
  594. void win_cmdfiles()   /* convert lpCmdLine into argc, argv */
  595. {
  596. int i, k;
  597. int argc;
  598. char *argv[10];
  599. unsigned char arg[501];   /* max 10 args, 450 chars total */
  600.  
  601. arg[0] = 0;
  602. for (i = 0; i < 10; i++)
  603.    argv[i] = &arg[0];
  604. argc = 1;
  605. strcpy(&arg[1],"winfract.exe");
  606. argv[argc-1] = &arg[1];
  607.  
  608. for (i = 0; i < 460 && win_lpCmdLine[i] != 0; i++)
  609.    arg[20+i] = win_lpCmdLine[i];
  610. arg[20+i] = 0;
  611. arg[21+i] = 0;
  612.  
  613. for (k = 20; arg[k] != 0; k++) {
  614.     while(arg[k] <= ' ' && arg[k] != 0) k++;
  615.     if (arg[k] == 0) break;
  616.     if (argc >= 10) break;
  617.     argc++;
  618.     argv[argc-1] = &arg[k];
  619.     while(arg[k] > ' ')k++;
  620.     arg[k] = 0;
  621.     }
  622.  
  623. cmdfiles(argc,argv);
  624.  
  625. }
  626.